<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<script type="text/javascript">
	$(function() {
		var $grid = $('#grid_dept');
		var $title = '部门';
		var $baseUrl = 'sys/dept';
		$grid.treegrid({
			title : $title + '列表',
			url : $baseUrl + '/treeGrid?sort=sort,asc',
			treeFolderCls : 'icon-dept',
			treeFolderOpenCls : 'icon-dept',
			treeFileCls : 'icon-dept',
			dialog : {
				url : $baseUrl,
				name : $title,
				create : {
					width : 400,
					height : 310
				},
				update : {
					width : 400,
					height : 310
				},
				role : {
					width : 880,
					height : 368,
					name : '设置角色',
					title : '设置部门角色',
					url : 'role',
					href : 'sys/role/dialog',
					buttons : [ $.dialog.buttons.save, $.dialog.buttons.close ],
					onSubmitSuccess : function(data, options) {
						$.dialog.close();
						var $grid = $('#grid_dept_role')
						$.crudgrid.gridMethod($grid, 'reload');
					}
				}
			},
			columns : [ [ $.fields.treeField, $.fields.description, $.fields.sort, $.fields.createTime, $.fields.lastModifyTime, $.fields.status ] ],
			toolbar : [ $.crudgrid.buttons.createByParent, $.crudgrid.buttons.update, $.crudgrid.buttons.remove, '-', {
				text : '角色',
				iconCls : 'icon-role',
				handler : function() {
					$.crudgrid.getGrid(this).datagrid('dialog.update', 'role');
				}
			}, '-', $.crudgrid.buttons.refresh ],
			onSelect : function(row) {
				$('#grid_dept_role').datagrid('unselectAll').datagrid('load', {
					'joinIds' : row.id
				});
				$('#grid_dept_position').datagrid('unselectAll').datagrid('load', {
					'joinIds' : row.id
				});
			}
		}).treegrid('filter.init');
	});
</script>
<script type="text/javascript">
	$(function() {
		var $grid = $('#grid_dept_role');
		var $title = '角色';
		var $baseUrl = 'sys/dept/role';
		$grid.datagrid({
			singleSelect : false,
			title : $title + '列表',
			url : $baseUrl + '/selected?sort=sort,asc',
			columns : [ [ $.fields.name, $.fields.status ] ],
			onClickRow : function(index, row) {
				$(this).datagrid('linkgrid.load', {
					linkgrid : $('#grid_dept_permission'),
					field : 'joinIds'
				});
			},
			onAjaxSuccess : function(data) {
				$(this).datagrid('selectAll');
				$(this).datagrid('linkgrid.load', {
					linkgrid : $('#grid_dept_permission'),
					field : 'joinIds'
				});
			},
			toolbar : [ $.crudgrid.buttons.refresh, '-' ]
		}).treegrid('filter.init');
	});
</script>
<script>
	$(function() {
		var $grid = $('#grid_dept_permission');
		var title = '权限';
		var $baseUrl = 'sys/permission';
		$grid.treegrid({
			border : false,
			singleSelect : false,
			title : title + '列表',
			url : $baseUrl + '/treeGrid?sort=sort,asc',
			onLoadSuccess : function(data) {
				$(this).treegrid('initSelected');
			},
			onBeforeSelect : function(row) {
				if (!row.selected) {
					return false;
				}
			},
			onBeforeUnselect : function(row) {
				return false;
			},
			columns : [ [ $.fields.permission.checkbox('permissionIds', true), $.fields.treeField, $.fields.status ] ],
			toolbar : [ $.crudgrid.buttons.refresh, '-' ]
		}).treegrid('filter.init');
	});
</script>
<script type="text/javascript">
	$(function() {
		var $grid = $('#grid_dept_position');
		var $title = '岗位';
		var $baseUrl = 'sys/dept/position';
		$grid.datagrid({
			singleSelect : false,
			title : $title + '列表',
			url : $baseUrl + '/selected?sort=sort,asc',
			columns : [ [ $.fields.name, {
				field : 'dept',
				width : 120,
				title : '来源',
				formatter : function(value, row, index) {
					return row.dept ? '部门' : '';
				}
			}, $.fields.status ] ],
			onClickRow : function(index, row) {
				$(this).datagrid('linkgrid.load', {
					linkgrid : $('#grid_dept_duty'),
					field : 'joinIds'
				});
			},
			onAjaxSuccess : function(data) {
				$(this).datagrid('linkgrid.load', {
					linkgrid : $('#grid_dept_duty'),
					field : 'joinIds'
				});
			},
			toolbar : [ $.crudgrid.buttons.refresh, '-' ]
		}).treegrid('filter.init');
	});
</script>
<script>
	$(function() {
		var $grid = $('#grid_dept_duty');
		var title = '职责';
		var $baseUrl = 'sys/duty';
		$grid.treegrid({
			border : false,
			singleSelect : false,
			title : title + '列表',
			url : $baseUrl + '/treeGrid?sort=sort,asc',
			onLoadSuccess : function(data) {
				$(this).treegrid('initSelected');
			},
			onBeforeSelect : function(row) {
				if (!row.selected) {
					return false;
				}
			},
			onBeforeUnselect : function(row) {
				return false;
			},
			columns : [ [ $.fields.permission.checkbox('dutyIds', true), $.fields.treeField, $.fields.status ] ],
			toolbar : [ $.crudgrid.buttons.refresh, '-' ]
		}).treegrid('filter.init');
	});
</script>
<div class="easyui-layout" data-options="fit:true">
	<div data-options="region:'center',split:true,border:false">
		<table id="grid_dept"></table>
	</div>
	<div data-options="region:'east',split:true" style="width: 390px;">
		<div class="easyui-tabs" data-options="fit:true">
			<div title="角色权限">
				<div class="easyui-layout" data-options="fit:true,border:false">
					<div data-options="region:'north',border:false" style="height: 300px;">
						<table id="grid_dept_role"></table>
					</div>
					<div data-options="region:'center'" style="width: 390px;">
						<table id="grid_dept_permission"></table>
					</div>
				</div>
			</div>
			<div title="岗位职责">
				<div class="easyui-layout" data-options="fit:true,border:false">
					<div data-options="region:'north',border:false" style="height: 300px;">
						<table id="grid_dept_position"></table>
					</div>
					<div data-options="region:'center'" style="width: 390px;">
						<table id="grid_dept_duty"></table>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>